package com.kgo.eidtor.service.impl;

import cn.hutool.core.util.IdUtil;
import com.kgo.eidtor.dao.StandardBeanMapper;
import com.kgo.eidtor.entity.StandardBean;
import com.kgo.eidtor.service.StandardService;
import com.kgo.eidtor.util.ResultUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author keepgoon
 * @Description: TODO
 * @date 2019/1/3114:07
 */
@Service
public class StandardServiceImpl implements StandardService {
    @Resource
    private StandardBeanMapper standardBeanMapper;
    @Override
    public int addStandard(StandardBean standard) {
        if (StringUtils.isBlank(standard.getId())){
            standard.setId(IdUtil.simpleUUID());
        }
        return standardBeanMapper.insert(standard);
    }

    /**
     * 该查询不包含文本内容，文本属于大文本，单独查询
     * @param standard
     * @return
     */
    @Override
    public String getStandards(StandardBean standard) {
        int count = standardBeanMapper.getStandardCount(standard);
        if (count>0){
            return ResultUtil.query(count,standardBeanMapper.getStandards(standard),"规范查询成功");
        }else{
            return ResultUtil.query(count,null,"无符合要求的规范数据");
        }
    }

    @Override
    public int getStandardCount(StandardBean standard) {
        return standardBeanMapper.getStandardCount(standard);
    }

    @Override
    public String getStandardById(String id) {
        if (StringUtils.isBlank(id)){
            return null;
        }
        return ResultUtil.query(1,standardBeanMapper.selectByPrimaryKey(id));
    }

    @Override
    public int deleteStandardById(String id) {
        return standardBeanMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateStandardById(StandardBean standard) {
        if(StringUtils.isBlank(standard.getId())){
            return -1;
        }
        return standardBeanMapper.updateByPrimaryKey(standard);
    }
}
